package com.item.yxlottery.yxlottery.activity;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.item.yxlottery.yxlottery.R;
import com.item.yxlottery.yxlottery.base.BaseActivity;
import com.item.yxlottery.yxlottery.views.ClearEditText;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by leo on 2017/1/5.
 */

public class RechargeActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.recharge_tv_username)
    TextView mTvUsername;//用户名
    @Bind(R.id.recharge_cet_rechargemoney)
    ClearEditText mCetRechargemoney;//充值金额
    @Bind(R.id.recharge_tv_money100)
    TextView mTvMoney100;
    @Bind(R.id.recharge_tv_money200)
    TextView mTvMoney200;
    @Bind(R.id.recharge_tv_money500)
    TextView mTvMoney500;
    @Bind(R.id.recharge_tv_money1000)
    TextView mTvMoney1000;
    @Bind(R.id.recharge_ll_wetchat)
    AutoLinearLayout mLlWetchat;//微信支付
    @Bind(R.id.recharge_ll_apay)
    AutoLinearLayout mLlApay;//支付宝支付
    @Bind(R.id.recharge_ll_unionpay)
    AutoLinearLayout mLlUnionpay;//银联支付

    @Override
    protected void setCustomActionBar(ImageButton ibActionbarLeft, TextView tvActionBarTitle, ImageButton ibActionbarRight, AutoRelativeLayout layoutActionbar) {
        ibActionbarLeft.setImageResource(R.drawable.leftarrow);
        ibActionbarLeft.setOnClickListener(this);
        ibActionbarRight.setVisibility(View.GONE);
        tvActionBarTitle.setText("充值");
    }

    @Override
    protected View initView() {
        View view = View.inflate(this, R.layout.activity_recharge, null);
        ButterKnife.bind(this,view);
        return view;
    }

    @Override
    protected void initData() {
        mCetRechargemoney.setSelection(mCetRechargemoney.getText().length());
    }

    @Override
    protected void initEvent() {
        mTvMoney100.setOnClickListener(this);
        mTvMoney200.setOnClickListener(this);
        mTvMoney500.setOnClickListener(this);
        mTvMoney1000.setOnClickListener(this);
        mLlWetchat.setOnClickListener(this);
        mLlApay.setOnClickListener(this);
        mLlUnionpay.setOnClickListener(this);

        mCetRechargemoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String ss = mCetRechargemoney.getText().toString().trim();
//                if (ss.equals("100")||ss.equals("200")||ss.equals("500")||ss.equals("1000")){
//                    Utils.log("------------------"+ss);
//                }else {
//                    changeView(ss);
//                }
                changeView(ss);
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ib_actionbar_left://返回
                finish();
                break;
            case R.id.recharge_tv_money100:
                mCetRechargemoney.setText("100");
            break;
            case R.id.recharge_tv_money200:
                mCetRechargemoney.setText("200");
                break;
            case R.id.recharge_tv_money500:
                mCetRechargemoney.setText("500");
                break;
            case R.id.recharge_tv_money1000:
                mCetRechargemoney.setText("1000");
                break;
            case R.id.recharge_ll_wetchat://微信

                break;
            case R.id.recharge_ll_apay://支付宝

                break;
            case R.id.recharge_ll_unionpay://银联

                break;
        }
    }

    private void changeView(String s) {

        if (s.equals("100")){
            mTvMoney100.setTextColor(getResources().getColor(R.color.white));
            mTvMoney100.setBackground(getResources().getDrawable(R.drawable.red_btn_bg));
            mTvMoney200.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney200.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney500.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney500.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney1000.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney1000.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mCetRechargemoney.setSelection(mCetRechargemoney.getText().length());
        }else if (s.equals("200")){
            mTvMoney200.setTextColor(getResources().getColor(R.color.white));
            mTvMoney200.setBackground(getResources().getDrawable(R.drawable.red_btn_bg));
            mTvMoney100.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney100.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney500.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney500.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney1000.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney1000.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mCetRechargemoney.setSelection(mCetRechargemoney.getText().length());
        }else if (s.equals("500")){
            mTvMoney500.setTextColor(getResources().getColor(R.color.white));
            mTvMoney500.setBackground(getResources().getDrawable(R.drawable.red_btn_bg));
            mTvMoney100.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney100.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney200.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney200.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney1000.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney1000.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mCetRechargemoney.setSelection(mCetRechargemoney.getText().length());
        }else if (s.equals("1000")){
            mTvMoney1000.setTextColor(getResources().getColor(R.color.white));
            mTvMoney1000.setBackground(getResources().getDrawable(R.drawable.red_btn_bg));
            mTvMoney100.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney100.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney200.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney200.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney500.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney500.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mCetRechargemoney.setSelection(mCetRechargemoney.getText().length());
        }else {
            mTvMoney100.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney100.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney200.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney200.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney500.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney500.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
            mTvMoney1000.setTextColor(getResources().getColor(R.color.text_gray_c6bebe));
            mTvMoney1000.setBackground(getResources().getDrawable(R.drawable.gray_line_bg));
        }


    }


}
